package threadcreate01;

import javax.xml.crypto.Data;
import java.util.Date;

public class thread02 {
    public static void main(String[] args) {
//        声明一个匿名内部类继承Thread类，重写run方法，实现打印[1,100]之间的偶数，要求每隔1秒打印1个偶数。
        new Thread("每隔一秒打印一个数字"){
            @Override
            public void run(){
                for (int i = 1; i <=100; i++) {
                    if(i%2==0)
                    {
                        System.out.println("线程名："+new Date());
                        System.out.println(i);
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
        }.start();
    }
}
